package cn.itcast.mq.cofing;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * RabbitMq 配置类
 *
 * @Author mr.Css
 * @Date 2025-01-05 10:59
 */
@Configuration
public class RabbitConfig {

    /**
     * 声明简单队列
     * @return
     */
    @Bean
    public Queue simpleQueue(){
        return new Queue("simple.queue");
    }
    /**
     * 声明工作队列
     * @return
     */
    @Bean
    public Queue workQueue(){
        return new Queue("work.queue");
    }

    /**
     *  声明广播队列1
     * @return
     */
    @Bean
    public Queue fanoutQueue1(){
        return new Queue("fanout.queue1");
    }
    /**
     *  声明广播队列2
     * @return
     */
    @Bean
    public Queue fanoutQueue2(){
        return new Queue("fanout.queue2");
    }
    /**
     * 声明广播交换机
     * @return
     */
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("itcast.fanout");
    }
    /**
     * 声明广播交换机和广播队列1的绑定关系
     * @return
     */
    @Bean
    public Binding bindFanoutQueue1(){
        return BindingBuilder.bind(fanoutQueue1()).to(fanoutExchange());
    }
    /**
     * 声明广播交换机和广播队列2的绑定关系
     * @return
     */
    @Bean
    public Binding bindFanoutQueue2(){
        return BindingBuilder.bind(fanoutQueue2()).to(fanoutExchange());
    }

    /**
     * 消息转换器(默认转换器)
     * @return
     */
    @Bean
    public Queue objectQueue(){
        return new Queue("object.queue");
    }
}
